package com.xu.sms.adapter;

import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xu.sms.R;
import com.xu.sms.entity.Type;
import com.xu.sms.utils.DateUtil;
import com.xu.sms.utils.LogUtil;

public class HotAdapter extends BaseAdapter {

	private Context context;
	private List<Type> typeList;
	private String TAG = HotAdapter.class.getSimpleName();
	
	public HotAdapter(Context context,List<Type> typeList){
		this.context = context;
		this.typeList = typeList;
	}
	
	public HotAdapter(){}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return typeList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return typeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if(convertView !=null){
			view = convertView;
		}else{
			view = View.inflate(context, R.layout.listview_item_hot, null);
		}
		//对控件进行填充数据
		setWidgetData(position, view);
		return view;
	}

	
	private void setWidgetData(int position, View view) {
		ImageView item_hot_iv_img = (ImageView) view.findViewById(R.id.item_hot_iv_img);
		TextView item_hot_tv_typeName = (TextView) view.findViewById(R.id.item_hot_tv_typeName);
		TextView item_hot_tv_typeTime = (TextView) view.findViewById(R.id.item_hot_tv_typeTime);
		TextView item_hot_tv_typedescription = (TextView) view.findViewById(R.id.item_hot_tv_typedescription);
		TextView item_hot_residueday = (TextView) view.findViewById(R.id.item_hot_residueday);
		Type type = typeList.get(position);
		item_hot_iv_img.setImageResource(type.getLocalImgId());
		String week = DateUtil.getDateWeek(type.getTypeTime());
		item_hot_tv_typeName.setText(type.getTypeName()+"	"+week);
		item_hot_tv_typeTime.setText(type.getTypeTimeStr());
		item_hot_tv_typedescription.setText(type.getTypeDescription());
		int day = DateUtil.dateAndDateDiff(new Date(), type.getTypeTime());
		item_hot_residueday.setText("还有"+day+"天");
	}
	
	

}






















